package com.bigshen.demo.annotation.configurecomponents.a5Imports;

import com.bigshen.demo.project.entity.Apple;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyRegistry implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // 包里同时声明了Apple 和 Orange ，才把Fruit放入IOC容器

        Boolean containsApple = registry.containsBeanDefinition("com.bigshen.demo.project.entity.Apple");
        Boolean containsOrange = registry.containsBeanDefinition("com.bigshen.demo.project.entity.Orange");

        if (containsApple && containsOrange) {
            BeanDefinition beanDefinition = new RootBeanDefinition(Apple.class);
            registry.registerBeanDefinition("apple", beanDefinition);
        }

    }

}
